﻿<Application x:Class="EmperialApps.WeatherSpark.App"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:agent="clr-namespace:EmperialApps.WeatherSpark.Agent;assembly=WeatherSpark.WPAgent"
             xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
             xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
             xmlns:System="clr-namespace:System;assembly=mscorlib">

    <!--Application Resources-->
    <Application.Resources>
        <resources:Localized xmlns:resources="clr-namespace:EmperialApps.WeatherSpark.Resources"
                             x:Key="Localized" />

        <SolidColorBrush x:Key="HumidityBrush"
                         Color="#FF30E6FF" />
        <SolidColorBrush x:Key="PressureBrush"
                         Color="#FFC48616" />
        <SolidColorBrush x:Key="PrecipitationBrush"
                         Color="#FF1BA1E2" />
        <SolidColorBrush x:Key="CloudCoverBrush"
                         Color="Gray" />
        <SolidColorBrush x:Key="WindBrush"
                         Color="LightGray" />

        <Thickness x:Key="SeparatorMargin">0,22,0,0</Thickness>

        <Style x:Key="SettingDescription"
               BasedOn="{StaticResource PhoneTextSubtleStyle}"
               TargetType="TextBlock">
            <Setter Property="Margin"
                    Value="{StaticResource SeparatorMargin}" />
        </Style>

        <Style x:Key="RoundButton"
               TargetType="Button">
            <Setter Property="Background"
                    Value="Transparent" />
            <Setter Property="BorderBrush"
                    Value="{StaticResource PhoneForegroundBrush}" />
            <Setter Property="Foreground"
                    Value="{StaticResource PhoneForegroundBrush}" />
            <Setter Property="BorderThickness"
                    Value="{StaticResource PhoneBorderThickness}" />
            <Setter Property="FontFamily"
                    Value="{StaticResource PhoneFontFamilySemiBold}" />
            <Setter Property="FontSize"
                    Value="{StaticResource PhoneFontSizeMediumLarge}" />
            <Setter Property="Margin"
                    Value="{StaticResource PhoneVerticalMargin}" />
            <Setter Property="Padding"
                    Value="5,0" />
            <Setter Property="HorizontalContentAlignment"
                    Value="Stretch" />
            <Setter Property="VerticalContentAlignment"
                    Value="Top" />
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid Background="Transparent">
                            <VisualStateManager.VisualStateGroups>
                                <VisualStateGroup x:Name="CommonStates">
                                    <VisualState x:Name="Normal" />
                                    <VisualState x:Name="MouseOver" />
                                    <VisualState x:Name="Pressed">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground"
                                                                           Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="{StaticResource PhoneForegroundBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground"
                                                                           Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="{StaticResource PhoneForegroundBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground"
                                                                           Storyboard.TargetProperty="BorderThickness">
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="0" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonImage"
                                                                           Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="{StaticResource PhoneBackgroundBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                    <VisualState x:Name="Disabled">
                                        <Storyboard>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ContentContainer"
                                                                           Storyboard.TargetProperty="Foreground">
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="{StaticResource PhoneDisabledBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground"
                                                                           Storyboard.TargetProperty="BorderBrush">
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="{StaticResource PhoneDisabledBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonImage"
                                                                           Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="{StaticResource PhoneDisabledBrush}" />
                                            </ObjectAnimationUsingKeyFrames>
                                            <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ButtonBackground"
                                                                           Storyboard.TargetProperty="Background">
                                                <DiscreteObjectKeyFrame KeyTime="0"
                                                                        Value="Transparent" />
                                            </ObjectAnimationUsingKeyFrames>
                                        </Storyboard>
                                    </VisualState>
                                </VisualStateGroup>
                            </VisualStateManager.VisualStateGroups>

                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto" />
                                <ColumnDefinition Width="*" />
                            </Grid.ColumnDefinitions>

                            <Border x:Name="ButtonBackground"
                                    Height="48"
                                    Margin="{StaticResource PhoneTouchTargetOverhang}"
                                    Width="48"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="30"
                                    VerticalAlignment="Top" />
                            <Border x:Name="ButtonImage"
                                    Height="48"
                                    Margin="{StaticResource PhoneTouchTargetOverhang}"
                                    Width="48"
                                    Background="{StaticResource PhoneForegroundBrush}"
                                    BorderBrush="{TemplateBinding BorderBrush}"
                                    BorderThickness="{TemplateBinding BorderThickness}"
                                    CornerRadius="30"
                                    OpacityMask="{TemplateBinding Background}"
                                    VerticalAlignment="Top" />

                            <ContentControl x:Name="ContentContainer"
                                            Grid.Column="1"
                                            Padding="{TemplateBinding Padding}"
                                            Content="{TemplateBinding Content}"
                                            ContentTemplate="{TemplateBinding ContentTemplate}"
                                            Foreground="{TemplateBinding Foreground}"
                                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style x:Key="TileProgressIndicator"
               TargetType="Shape">
            <Setter Property="Width"
                    Value="24" />
            <Setter Property="Height"
                    Value="24" />
            <Setter Property="Margin"
                    Value="12,17" />
            <Setter Property="HorizontalAlignment"
                    Value="Right" />
            <Setter Property="VerticalAlignment"
                    Value="Top" />
            <Setter Property="Fill"
                    Value="{StaticResource PhoneAccentBrush}" />
        </Style>

        <DataTemplate x:Key="TileTemplate">
            <StackPanel Orientation="Horizontal">
                <Grid Height="173"
                      Background="{StaticResource PhoneAccentBrush}">
                    <Viewbox>
                        <agent:TileImage BackgroundColor="{Binding BackgroundColor}"
                                         DisplayMode="{Binding DisplayMode}"
                                         Forecast="{Binding Forecast}"
                                         ImageSource="{Binding ImageSource}"
                                         IsHitTestVisible="False"
                                         Title="{Binding TileTitle}"
                                         Units="{Binding LocationSettings.Units}" />
                    </Viewbox>
                </Grid>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="TileBackTemplate">
            <StackPanel Orientation="Horizontal">
                <Grid Height="173"
                      Background="{StaticResource PhoneAccentBrush}">
                    <Viewbox>
                        <agent:TileFlipImage BackgroundColor="{Binding BackgroundColor}"
                                             DisplayMode="{Binding DisplayMode}"
                                             Forecast="{Binding Forecast}"
                                             ImageSource="{Binding ImageSource}"
                                             IsHitTestVisible="False"
                                             Title="{Binding TileTitle}"
                                             Units="{Binding LocationSettings.Units}" />
                    </Viewbox>
                </Grid>
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="TileHorizontalTemplate">
            <StackPanel Orientation="Horizontal">
                <ContentPresenter Margin="{StaticResource PhoneTouchTargetOverhang}"
                                  Content="{Binding}"
                                  ContentTemplate="{StaticResource TileTemplate}" />
                <TextBlock Margin="{StaticResource PhoneHorizontalMargin}"
                           FontSize="{StaticResource PhoneFontSizeLarge}"
                           Text="{Binding DisplayModeTitle}"
                           VerticalAlignment="Center" />
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="TileBackHorizontalTemplate">
            <StackPanel Orientation="Horizontal">
                <ContentPresenter Margin="{StaticResource PhoneTouchTargetOverhang}"
                                  Content="{Binding}"
                                  ContentTemplate="{StaticResource TileBackTemplate}" />
                <TextBlock Margin="{StaticResource PhoneHorizontalMargin}"
                           FontSize="{StaticResource PhoneFontSizeLarge}"
                           Text="{Binding EnabledTitle}"
                           VerticalAlignment="Center" />
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="TileVerticalTemplate">
            <StackPanel Orientation="Vertical">
                <ContentPresenter Margin="{StaticResource PhoneTouchTargetOverhang}"
                                  Content="{Binding}"
                                  ContentTemplate="{StaticResource TileTemplate}" />
                <TextBlock Margin="{StaticResource PhoneHorizontalMargin}"
                           FontSize="{StaticResource PhoneFontSizeLarge}"
                           Text="{Binding DisplayModeTitle}"
                           HorizontalAlignment="Center" />
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="TileBackVerticalTemplate">
            <StackPanel Orientation="Vertical">
                <ContentPresenter Margin="{StaticResource PhoneTouchTargetOverhang}"
                                  Content="{Binding}"
                                  ContentTemplate="{StaticResource TileBackTemplate}" />
                <TextBlock Margin="{StaticResource PhoneHorizontalMargin}"
                           FontSize="{StaticResource PhoneFontSizeLarge}"
                           Text="{Binding EnabledTitle}"
                           HorizontalAlignment="Center" />
            </StackPanel>
        </DataTemplate>

        <DataTemplate x:Key="TileItemTemplate">
            <Border Background="{StaticResource PhoneSemitransparentBrush}">
                <ContentPresenter Margin="-4,0,4,0"
                                  Content="{Binding}"
                                  ContentTemplate="{StaticResource TileVerticalTemplate}" />
            </Border>
        </DataTemplate>

        <DataTemplate x:Key="TileBackItemTemplate">
            <Border Background="{StaticResource PhoneSemitransparentBrush}">
                <ContentPresenter Margin="-4,0,4,0"
                                  Content="{Binding}"
                                  ContentTemplate="{StaticResource TileBackVerticalTemplate}" />
            </Border>
        </DataTemplate>
    </Application.Resources>

    <Application.ApplicationLifetimeObjects>
        <!--Required object that handles lifetime events for the application-->
        <shell:PhoneApplicationService Activated="Application_Activated"
                                       Closing="Application_Closing"
                                       Deactivated="Application_Deactivated"
                                       Launching="Application_Launching" />
    </Application.ApplicationLifetimeObjects>
</Application>
